<template>
	<view class="StudyPlan" :class="{'theme--Black':CurrentTheme.name==='DarkMode'}">
		<!-- 导航栏 -->
		<u-navbar title-color="#fff" back-icon-color="#ffffff" is-back="true" :background="background" :back-text-style="{ color: '#fff' }"
		 title="数据统计" back-icon-name="nav-back">
			<view class="navbar-right" slot="right">
				<view class="dot-box right-item fo-white paddlr20" @click="onAdd">
					<!-- <text class="cuIcon-roundadd fo-46"></text> -->
				</view>
			</view>
		</u-navbar>

		<!-- 主要内容 -->
		<contentS :list='data_list'></contentS>
		<u-tabbar v-model="current" :list="TarbarList" :mid-button="false" @change='onTarBarChange'></u-tabbar>
	</view>
</template>

<script>
	import contentS from './component/content/index.vue'
	export default {
		name: "",
		components: {
			contentS
		},
		data() {
			return {
				background: {
					background: '#87ceeb'
				},
				list: [], // 传给组件的数据

				TarbarList: [{
						iconPath: "home",
						selectedIconPath: "home-fill",
						text: '首页',
						isDot: true,
						customIcon: false,
					},
					{
						iconPath: "grid",
						selectedIconPath: "grid-fill",
						text: '可视化分析',
						customIcon: false,
					}
				],
				current: 1,


				data_list: {
					pieData: [{
						"name": "一班(1小时5分钟)",
						"data": 1.5
					},{
						"name": "一班(1小时5分钟)",
						"data": 5.5
					},{
						"name": "一班(1小时5分钟)",
						"data": 5.5
					},{
						"name": "一班(1小时5分钟)",
						"data": 5.5
					},{
						"name": "一班(1小时5分钟)",
						"data": 5.5
					},{
						"name": "一班(1小时5分钟)",
						"data": 5.5
					},{
						"name": "一班(1小时5分钟)",
						"data": 5.5
					},{
						"name": "一班(1小时5分钟)",
						"data": 5.5
					},{
						"name": "一班(1小时5分钟)",
						"data": 5.5
					}],
					Current: { // 当日模块
						count: 0,
						duration: 0,
						dayDuration: 0,
					},
					Cumulative: { // 累计模块
						count: 0, //次数
						duration: 0, //总时长
						dayDuration: 0, // 日均时长
					}
				}
			}
		},
		onReady() {
			// 初始化加载本地缓存数据
			let listData = this.$pub.getStorageSync('StudyPlane')
			let D = new Date();
			let CumulativeCount = 0,
				CumulativeDuration = 0,
				CurrentCount = 0,
				CurrentDuration = 0;

			listData.forEach(i => {
				/*
					计算累计模块的  次数和总时长
				*/ 
				CumulativeCount += i.Child.length;
				let FatherArr = i.times.split('.').map(Number);
				CumulativeDuration += FatherArr[0] * 24 + FatherArr[1];

				i.Child.forEach(ii => {
					/*
						计算当日模块的  次数和日总时长
					*/ 
					let CurrentDateTimeStart = new Date(`${D.getFullYear()}-${D.getMonth()+1}-${D.getDate()} 00:00:00`).getTime()
					let CurrentDateTimeEnd = new Date(`${D.getFullYear()}-${D.getMonth()+1}-${D.getDate()} 23:59:59`).getTime()
					if(CurrentDateTimeStart<=ii.OpearteTime && CurrentDateTimeEnd>=ii.OpearteTime){
						CurrentCount++
						let ChildArr = ii.StudyTime.split('.').map(Number);
						CurrentDuration += (ChildArr[0] + ChildArr[1]/60); // 累加 累计模块的总时长 					
					}
				})
			})
			
			
			// 赋值部分
			this.data_list.Cumulative.count = CumulativeCount;
			this.data_list.Cumulative.duration = CumulativeDuration;
			this.data_list.Cumulative.dayDuration = Number((CumulativeDuration / CumulativeCount).toFixed(2)) || 0
			
			this.data_list.Current.count = CurrentCount;
			this.data_list.Current.duration = CurrentDuration;
			
		},
		onLoad() {
			this.background.background = this.CurrentTheme.navColor
		},
		methods: {
			// 导航栏按钮
			onAdd() {

			},
			// 底部跳转
			onTarBarChange(e) {
				if (e === 0) {
					this.$pub.redirTo('/pages/other/StudyPlane/index')
				}
			}
		}
	}
</script>

<style scoped lang="less">

	.StudyPlan {
		height: 100vh;
		padding: 20rpx;
		overflow: scroll;
		/* #ifdef APP-PLUS */
		background-color: #f5f5f5;
		/* #endif */
	}

	/* 弹窗部分 */
	.pop-head {
		padding: 20rpx 20rpx;
		background-color: skyblue;
		border-radius: 10rpx 10rpx 0 0;
	}
</style>
